package com.liusha.vinfoaddins.vinfoaddins;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.liusha.vinfoaddins.vinfoaddins.fragment.MainAlreadyUploadFragment;
import com.liusha.vinfoaddins.vinfoaddins.fragment.MainHomeFragment;
import com.liusha.vinfoaddins.vinfoaddins.fragment.MainPendingUploadFragment;
import com.liusha.vinfoaddins.vinfoaddins.fragment.MainSettingFragment;
import com.liusha.vinfoaddins.vinfoaddins.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.vp)
    NoScrollViewPager mVp;
    @BindView(R.id.iv_1)
    ImageView mIv1;
    @BindView(R.id.tv_1)
    TextView mTv1;
    @BindView(R.id.ll_1)
    LinearLayout mLl1;
    @BindView(R.id.iv_2)
    ImageView mIv2;
    @BindView(R.id.tv_2)
    TextView mTv2;
    @BindView(R.id.ll_2)
    LinearLayout mLl2;
    @BindView(R.id.iv_3)
    ImageView mIv3;
    @BindView(R.id.tv_3)
    TextView mTv3;
    @BindView(R.id.ll_3)
    LinearLayout mLl3;
    @BindView(R.id.iv_4)
    ImageView mIv4;
    @BindView(R.id.tv_4)
    TextView mTv4;
    @BindView(R.id.ll_4)
    LinearLayout mLl4;

    private List<Fragment> mFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setBtn(mIv1, mTv1);
        mFragments=new ArrayList<>();
        mFragments.add(new MainHomeFragment());
        mFragments.add(new MainPendingUploadFragment());
        mFragments.add(new MainAlreadyUploadFragment());
        mFragments.add(new MainSettingFragment());

        mVp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        });
    }

    @OnClick({R.id.ll_1, R.id.ll_2, R.id.ll_3, R.id.ll_4})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_1:
                setBtn(mIv1, mTv1);
                mVp.setCurrentItem(0,false);
                break;
            case R.id.ll_2:
                setBtn(mIv2, mTv2);
                mVp.setCurrentItem(1,false);
                break;
            case R.id.ll_3:
                setBtn(mIv3, mTv3);
                mVp.setCurrentItem(2,false);
                break;
            case R.id.ll_4:
                setBtn(mIv4, mTv4);
                mVp.setCurrentItem(3,false);
                break;
        }
    }

    private void setBtn(ImageView iv,TextView tv){
        mIv1.setEnabled(true);
        mTv1.setEnabled(true);
        mIv2.setEnabled(true);
        mTv2.setEnabled(true);
        mIv3.setEnabled(true);
        mTv3.setEnabled(true);
        mIv4.setEnabled(true);
        mTv4.setEnabled(true);

        iv.setEnabled(false);
        tv.setEnabled(false);
    }
}
